Skip to content

Conversation

@mokarchi
Copy link

How It Works

When you call new ArchLoader().LoadAssemblies(...).Build(), ArchUnitNET automatically:

  1. Creates a cache key based on the modules being loaded and any namespace filters applied
  2. Checks the cache for a previously loaded Architecture instance matching this key
  3. Returns the cached instance if found, or loads and caches a new instance if not

This means that loading the same assemblies multiple times (even with different ArchLoader instances) will reuse the cached Architecture object, providing dramatic performance improvements.

Usage Examples

Basic usage (automatic caching with file-based invalidation):

var arch = new ArchLoader()
    .LoadAssemblies(assembly)
    .Build(); // Automatically cached with invalidation

Custom cache key for test isolation:

var arch = new ArchLoader()
    .WithUserCacheKey("test-run-1")
    .LoadAssemblies(assembly)
    .Build();

Disable caching for specific scenarios:

var arch = new ArchLoader()
    .WithoutCaching()
    .LoadAssemblies(assembly)
    .Build();

Advanced configuration (config is cloned internally):

var config = new ArchLoaderCacheConfig
{
    CachingEnabled = true,
    UseFileBasedInvalidation = true, // Check file changes
    UserCacheKey = "integration-tests",
    IncludeVersionInCacheKey = true // Invalidate on version change
};

var arch = new ArchLoader()
    .WithCacheConfig(config)
    .LoadAssemblies(assembly)
    .Build();

// Safe: modifying config after passing it won't affect the ArchLoader
config.UserCacheKey = "different-key";

alexanderlinne and others added 2 commits October 25, 2025 08:37
Signed-off-by: Alexander Linne <[email protected]>
Signed-off-by: mokarchi <[email protected]>
Introduced a new caching system via `ArchitectureCacheManager` to improve performance and efficiency of `ArchLoader` builds. The caching mechanism supports file-based invalidation, user-defined cache keys, and version-based cache invalidation.

Key changes:
- Added `ArchitectureCacheManager` for centralized caching.
- Introduced `ArchLoaderCacheConfig` for configurable caching options.
- Added `AssemblyMetadata` to track assembly file changes.
- Enhanced `ArchBuilder` with a new `Build` method supporting caching.
- Improved `ArchLoader` with fluent API methods for caching configuration.
- Added extensive unit tests to validate caching behavior and performance.

Refactored code to integrate caching seamlessly while maintaining backward compatibility. Improved performance for repeated builds of the same assemblies.

Signed-off-by: mokarchi <[email protected]>
@mokarchi
Copy link
Author

@alexanderlinne Could you review this, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants